package com.ml.mall.mapper.sys;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.page.Page;
import com.ml.mall.bean.req.sys.SysUserQueryDto;
import com.ml.mall.bean.req.sys.SysUserQueryOneDto;
import com.ml.mall.bean.res.sys.SysUserRes;
import com.ml.mall.bean.res.sys.UserQueryInfoRes;
import com.ml.mall.entity.sys.SysPermission;
import com.ml.mall.entity.sys.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author kyyang
* Created 2021-01-05
*/
    @Mapper
    @Repository
public interface SysUserMapper extends BaseMapper<SysUser> {

    @Select("select * from sys_user where acc = #{acc}")
    SysUser selectByAccount(@Param("acc") String userName);

    List<SysPermission> selectCurrentPer(@Param("userId") Long userId, @Param("permissionId") Integer permissionId);

    List<SysPermission> selectCurrentMenu(@Param("userId") Long userId);

    @Select("select acc from sys_user where company_id = #{companyId}")
    List<String> selectByMerchantId(@Param("companyId") Long companyId);

//    List<SysUserVO> selectAccPages(@Param("dto") SysUserQueryDto dto);

    @Select("select * from sys_user where email=#{email} ")
    SysUser selectAccByEmail(@Param("email") String email);

    @Update("update sys_user set state = #{state} where company_id = #{companyId}")
    int updateAccState(@Param("companyId") Long companyId, @Param("state") int state);

    @Select("select acc,name from sys_user where company_id=#{companyId} ")
    SysUser selectByDealerId(@Param("companyId") Long companyId);

    @Select("select salt from sys_user where acc=#{acc} ")
    String selectSaltForForgetPwd(@Param("acc") String acc);

    /**
     * 分页查询用户
     * @param dto
     * @return
     */
    List<SysUserRes> selectPageUser(@Param("dto")SysUserQueryDto dto);

    /**
     * 统计用户数
     * @return
     */
    Integer countUser(@Param("dto")SysUserQueryDto dto);

    /**
     * 查询单个用户
     * @param dto
     * @return
     */
    UserQueryInfoRes selectOne(@Param("dto") SysUserQueryOneDto dto);

    SysUser selectOneByEmail(@Param("email") String email);
}
